package main

import (
	"fmt"
	"strconv"
)

func createDigit(a, b int) int {
	num := strconv.Itoa(a) + strconv.Itoa(b)

	itoa, _ := strconv.Atoi(num)
	return itoa
}

func checkShouldSplit(a int) bool {
	num1 := strconv.Itoa(a)
	num2 := strconv.Itoa(a + 1)

	if num1[0] != num2[0] {
		return true
	}

	return false

}

func numAdd(num int) int {
	if checkShouldSplit(num) {
		num -= 9
		num = createDigit(num, 0)
	} else {
		num++
	}

	return num
}

func createNum(i, index, maxNum int, arr []int) int {
	num := i
	arr[index] = num
	index++

	num = createDigit(num, 0)
	for true {
		if num > maxNum {
			break
		}
		arr[index] = num
		num = numAdd(num)
		index++
	}

	return index
}

func lexicalOrder(n int) []int {
	data := make([]int, n)
	index := 0
	for i := 1; i <= 9 && i <= n; i++ {
		index = createNum(i, index, n, data)
	}
	return data
}

func main() {
	fmt.Println(lexicalOrder(2))

}
